package com.ln.第二遍1027.demo003;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/10/27 17:14
 */
public class Test003 {
    public static void main(String[] args) throws Exception{
        Class<Student> studentClass = Student.class;
        Student student = studentClass.newInstance();
        System.out.println("student = " + student);

        Field age = studentClass.getDeclaredField("age");
        age.set(student,18);
        System.out.println(student);
        Object o = age.get(student);
        System.out.println("o = " + o);

        Field sex = studentClass.getDeclaredField("sex");
        sex.setAccessible(true);
        sex.set(student,"女");
        System.out.println(student);
        Object o1 = sex.get(student);
        System.out.println("o1 = " + o1);

    }
}
class Garden{
    private String name;
    public String address;

}
class Student extends Garden {
    private String sex;
    public int age;

    @Override
    public String toString() {
        return "Student{" +
                "sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }
}

